<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>新闻管理</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/dist/css/AdminLTE.min.css">
  <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
        page. However, you can choose any other skin. Make sure you
        apply the skin class to the body tag so the changes take effect.
  -->
  <link rel="stylesheet" href="/dist/css/skins/skin-blue.min.css">
  <style>
    .aa{
      margin: 10px 10px;
    }
    .bb{
      text-align: center;
      height: 400px
    }
    #content{
      width: 624px;
      margin: 10px 10px;
      height: 200px;
    }
    .mm{
      margin-top: 20px
    }
    .kind{
      margin: 0 10px;
      color:white
    }
    .modal-body .cc{
      width: 300px;
      margin-bottom: 8px;
      height:40px
    }
    /* .modal-body .ccc{
      width: 600px;
    } */
    
  </style>
</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- Main Header -->
  <%- include('./header.ejs') %>
  <!-- Left side column. contains the logo and sidebar -->
  <%- include('./menu.ejs') %>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        新闻数据库
        <small>娱乐，生活，军事，最新</small>
      </h1>
    </section>

    <!-- Main content -->
    <section class="content">

      <div class="box">
          <div class="box-header">
              <button type="button" class="btn btn-primary btn btn-primary" data-toggle="modal" data-target="#myModal">
                  添加数据
              </button>
                
                <!-- Modal -->
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                  <div class="modal-dialog" role="document">
                    <div class="modal-content" style="width:800px">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">添加信息</h4>
                      </div>
                      <div class="modal-body">
                          <form class="form-inline" action="/news/add" method="get">
                            <div class="form-group bb">
                              <div class="form-group aa">
                                <label class="sr-only" for="title">ID</label>
                                <input type="text" class="form-control cc" name="tid" id="tid" placeholder="ID">
                              </div>
                            <div class="form-group aa">
                              <label class="sr-only" for="image">image</label>
                              <input type="text" class="form-control cc" name="image" id="image" placeholder="图片">
                            </div>
                            <div class="form-group aa">
                              <label class="sr-only" for="title">标题</label>
                              <input type="text" class="form-control cc" name="title" id="title" placeholder="标题">
                            </div>
                            <div class="form-group aa">
                              <label class="sr-only" for="type">分类</label>
                              <input type="text" class="form-control cc" name="type" id="type" placeholder="分类">
                            </div>
                            <div class="form-group aa">
                              <label class="sr-only" for="time">时间</label>
                              <input type="text" class="form-control cc" name="time" id="time" placeholder="时间">
                            </div>
                            <div class="form-group aa">
                              <label class="sr-only" for="where">来源</label>
                              <input type="text" class="form-control cc" name="where" id="where" placeholder="来源">
                            </div>
                           
                            <div class="form-group aa">
                              <label class="sr-only" for="content">内容</label>
                              <textarea class="form-control ccc" rows="3" type="text" class="form-control" name="content" id="content" placeholder="内容"></textarea>
                            </div>

                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="submit" class="btn btn-info">添加记录</button>
                      </div>
                    </form>
                    </div>
                  </div>
                </div>
              </div>
              <ul style="list-style:none" class="btn btn-danger btn-sm"> 
                <% for(var item of kind) { %>
                  <li style="display: inline-block">
                    <a href="/news/type?num=<%= item %>" class="kind"> <%= item %> </a>
                  </li>
                <% } %>
              </ul>
              <form class="form-inline" style="float:right" action="/news/search" method="get">
                <div class="form-group">
                  <label class="sr-only" for="title">title</label>
                  <input type="text" class="form-control" name="title" id="title" placeholder="搜索标题">
                </div>
                <button type="submit" class="btn btn-info btn-sm">搜索</button>
              </form>
              <!-- /.box-header -->
              <div class="box-body no-padding">
                <table class="table table-striped table table-bordered table table-striped text-center">
                  <tbody><tr>
                    <th>ID</th>
                    <th>图片</th>
                    <th style="width:60px;">标题</th>
                    <th>内容</th>
                    <th>分类</th>
                    <th>时间</th>
                    <th>来源</th>
                    <th>操作</th>
                  </tr>
                  <% for (var i = 0; i< result.length; i++) { %>
                  <tr>
                    <td style="display:none"><%= i %></td>
                    <td><%= result[i].tid %></td>
                    <td style="width:100px;height:100px;"><img src="<%= result[i].image %>" style="width:100px;height:100px;"/></td>
                    <td id="test<%= i %>" style="width:100px">
                      <!-- <a href="/news/detail?tid=<%= result[i].tid %>"> -->
                        <%= result[i].title %>
                      <!-- </a> -->
                      </td>
                    <td id="test<%= i %>"><%= result[i].content %></td>
                    <td><%= result[i].type %></td>
                    <td><%= result[i].time %></td>
                    <td><%= result[i].where %></td>
                    <td> <button class="btn btn-warning btn-xs mm" onclick="edit('<%= i %>','<%= result[i].tid %>', '<%= result[i].title %>')">编辑</button>
                      <a href="/news/delete?tid=<%= result[i].tid %>"><button class="btn btn-success btn btn-primary btn-xs">删除</button></a>
                      </td>
                  </tr>
                  <% } %>
                </tbody></table>
              </div>
              <!-- /.box-body -->
            </div>

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  <!-- Main Footer -->
  <footer class="main-footer">
    <!-- To the right -->
    <div class="pull-right hidden-xs">
      Anything you want
    </div>
    <!-- Default to the left -->
    <strong>Copyright &copy; 2016 <a href="#">Company</a>.</strong> All rights reserved.
  </footer>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Create the tabs -->
    <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
      <li class="active"><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
      <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
    </ul>
    <!-- Tab panes -->
    <div class="tab-content">
      <!-- Home tab content -->
      <div class="tab-pane active" id="control-sidebar-home-tab">
        <h3 class="control-sidebar-heading">Recent Activity</h3>
        <ul class="control-sidebar-menu">
          <li>
            <a href="javascript::;">
              <i class="menu-icon fa fa-birthday-cake bg-red"></i>

              <div class="menu-info">
                <h4 class="control-sidebar-subheading">Langdon's Birthday</h4>

                <p>Will be 23 on April 24th</p>
              </div>
            </a>
          </li>
        </ul>
        <!-- /.control-sidebar-menu -->

        <h3 class="control-sidebar-heading">Tasks Progress</h3>
        <ul class="control-sidebar-menu">
          <li>
            <a href="javascript::;">
              <h4 class="control-sidebar-subheading">
                Custom Template Design
                <span class="pull-right-container">
                  <span class="label label-danger pull-right">70%</span>
                </span>
              </h4>

              <div class="progress progress-xxs">
                <div class="progress-bar progress-bar-danger" style="width: 70%"></div>
              </div>
            </a>
          </li>
        </ul>
        <!-- /.control-sidebar-menu -->

      </div>
      <!-- /.tab-pane -->
      <!-- Stats tab content -->
      <div class="tab-pane" id="control-sidebar-stats-tab">Stats Tab Content</div>
      <!-- /.tab-pane -->
      <!-- Settings tab content -->
      <div class="tab-pane" id="control-sidebar-settings-tab">
        <form method="post">
          <h3 class="control-sidebar-heading">General Settings</h3>

          <div class="form-group">
            <label class="control-sidebar-subheading">
              Report panel usage
              <input type="checkbox" class="pull-right" checked>
            </label>

            <p>
              Some information about this general settings option
            </p>
          </div>
          <!-- /.form-group -->
        </form>
      </div>
      <!-- /.tab-pane -->
    </div>
  </aside>
  
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="/bootstrap/js/bootstrap.min.js"></script>
<!-- AdminLTE App -->
<script src="/dist/js/app.min.js"></script>

<script type="text/javascript">
  function edit (index, tid, title) {
    // console.log(username, index)
    $('#test' + index).html(`
      <input type="text" name="title" id="title${index}" value="${title}" />
      <button id="btn${index}" class="btn btn-danger btn-xs" >确定</button>`)

    $("#btn" + index).on('click', function () {
      //console.log(username, index)
      var runNum = $('#title' + index).val();
      window.location.href = `/news/updateOne?tid=${tid}&title=${runNum}`;
    })
  }
</script>
</body>
</html>


